package org.jeecg.common.file;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.multipart.support.StandardServletMultipartResolver;

import javax.servlet.http.HttpServletRequest;

/**
 * 文件操作传参常量
 *
 * @author jiangtianyi
 * @version 1.0
 * @date 2023-03-02
 */
public class FileRequestCommon {

    public static final String BIZ = "biz";

    public static final String FILE = "file";

    public static final String FILE_NAME = "fileName";

    /**
     * 静态获取 MultipartHttpServletRequest
     *
     * @return {@link MultipartHttpServletRequest}
     * @author jiangtianyi
     * @since 1.0
     */
    public static MultipartHttpServletRequest getMultipartHttpServletRequest() {
        HttpServletRequest httpServletRequest = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest();
        StandardServletMultipartResolver resolver = new StandardServletMultipartResolver();
        return resolver.resolveMultipart(httpServletRequest);
    }

}
